<?php

class city_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "city";
    }

    function insert($cityid, $citynama, $cityibukota, $provinceid) {
        $dt = array("cityid" => $cityid,
            "citynama" => $citynama,
            "cityibukota" => $cityibukota,
            "provinceid" => $provinceid);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }

    function update($cityid, $provinceid, $dt, $where = "") {
        $this->db->where("cityid", $cityid);
        $this->db->where("provinceid", $provinceid);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($cityid, $provinceid, $where = "") {
        $this->db->where("cityid", $cityid);
        $this->db->where("provinceid", $provinceid);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($cityid, $provinceid, $where = "") {
        $this->db->where("cityid", $cityid);
        $this->db->where("provinceid", $provinceid);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get($this->tableName)->row();
    }

    function getAll($startpage = "0", $perpage = "10", $where = "", $orderby = "") {
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        return $this->db->get($this->tableName)->result();
    }

    function getAllCount($where = "") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row()->JUMLAH;
    }
    function getByProp($propinsiid,  $where=""){
        $this->db->where("province_id", $propinsiid);
        if($where != "")$this->db->where($where);
        return $this->db->get($this->tableName)->result();
    }

}

?>